package com.sk.bilibili.view.fragment.main.home.home;

import android.view.View;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.sk.bilibili.adapter.vlayout.HorizontalAdapter;
import com.sk.bilibili.adapter.vlayout.main.FollowAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.HeaderAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.HotAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.RefreshAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.TypeAdapter;
import com.sk.bilibili.adapter.vlayout.BannerAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.WatchFullAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.film.PropagandaAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.film.RankAdapter;
import com.sk.bilibili.bean.FollowThem;
import com.sk.bilibili.bean.Propaganda;
import com.sk.bilibili.bean.Them;
import com.sk.bilibili.bean.ThemBanner;
import com.sk.bilibili.callBack.BannerClickCallBack;
import com.sk.bilibili.callBack.ThemClickCallBack;
import com.sk.bilibili.callBack.TypeClickCallBack;
import com.sk.bilibili.dto.Extra;
import com.sk.bilibili.model.fragment.main.home.home.FilmModel;
import com.sk.bilibili.utils.IntentUtils;
import com.sk.bilibili.view.activity.RankActivity;
import com.sk.bilibili.view.activity.ThemActivity;
import com.sk.bilibili.view.fragment.BaseRefreshFragment;

import java.util.Arrays;
import java.util.List;

public class FilmFragment extends BaseRefreshFragment<FilmModel> implements BannerClickCallBack, TypeClickCallBack, ThemClickCallBack, View.OnClickListener {

    private BannerAdapter bannerAdapter;
    private TypeAdapter typeAdapter;
    private HorizontalAdapter<FollowThem> followAdapter;
    private RankAdapter rankAdapter;
    private HotAdapter hotAdapter;
    private PropagandaAdapter propagandaAdapter;

    @Override
    protected void initAdapter(DelegateAdapter adapter) {
        bannerAdapter = new BannerAdapter(getContext(), this);
        adapter.addAdapter(bannerAdapter);
        typeAdapter = new TypeAdapter(getContext(), this);
        adapter.addAdapter(typeAdapter);
        adapter.addAdapter(new HeaderAdapter(getContext(), "我的追剧"));
        followAdapter = new HorizontalAdapter<>(getContext(), new FollowAdapter(getContext(),
                this));
        adapter.addAdapter(followAdapter);
        adapter.addAdapter(new HeaderAdapter(getContext(), "热门榜单"));
        rankAdapter = new RankAdapter(getContext(), this);
        adapter.addAdapter(rankAdapter);
        WatchFullAdapter fullAdapter = new WatchFullAdapter(getContext(), "查看完整榜单\u0006>");
        adapter.addAdapter(fullAdapter);
        fullAdapter.setListener(this);
        adapter.addAdapter(new HeaderAdapter(getContext(),"热门推荐"));
        hotAdapter = new HotAdapter(getContext(), this);
        adapter.addAdapter(hotAdapter);
        adapter.addAdapter(new HeaderAdapter(getContext(),"独家策划"));
        propagandaAdapter=new PropagandaAdapter(getContext(),this);
        adapter.addAdapter(propagandaAdapter);
    }

    @Override
    public void onFollowClick(Integer id) {
        model.followThem(id);
    }

    @Override
    public void onBannerClick(String url) {
        IntentUtils.startUrl(getContext(),url);
    }

    @Override
    public void onTypeClick(int pos) {
        toast("TYPE:"+pos);
    }

    public void loadBannerSuccess(List<ThemBanner> themBanners) {
        bannerAdapter.setList(themBanners);
        cancelRefresh();
    }

    @Override
    public void onThemClick(Integer themId, int selection) {
        ThemActivity.start(getContext(), themId,selection);
    }

    public void loadFollowThemSuccess(List<FollowThem> records) {
        followAdapter.setList(records);
    }

    public void loadRankSuccess(List<Them> list) {
        rankAdapter.setData(list);
    }

    public void loadHotThemSuccess(List<Them> list) {
        hotAdapter.setData(list);
    }

    public void loadPropagandaSuccess(List<Propaganda> propagandas) {
        propagandaAdapter.setData(propagandas);
    }

    public void loadTypeSuccess(List<Extra> list) {
        typeAdapter.setData(list);
    }

    public void followThemSuccess() {
        toast("自己追的番一定要看完欧");
    }

    @Override//点击查看完整排行帮回调
    public void onClick(View v) {
        RankActivity.start(getContext(),2);
    }

}